﻿@page "/configure"

<h4>Manage Runs</h4>

<div class="container-fluid bg-custom py-1">
    <div class="form-inline py-1">
        <label class="mr-2" for="CollectionRunsSelect">Collection Runs:</label>
        <select class="form-control mr-3" id="CollectionRunsSelect" @bind="SelectedRun">
            @for (int i = 0; i < Runs.Count; i++)
            {
                <option value="@i">@Runs[i]</option>
            }
        </select>
        <button class="btn btn-primary" @onclick="DeleteSelected">Delete Run</button>
    </div>
    <div class="form-inline py-1">
        <label class="mr-2" for="CompareRunsSelect">Comparison Runs:</label>
        <select class="form-control mr-3" id="CompareRunsSelect" @bind="SelectedCompareRun">
            @for (int i = 0; i < CompareRuns.Count; i++)
            {
                <option value="@i">@CompareRuns[i]</option>
            }
        </select>
        <button class="btn btn-primary" @onclick="DeleteSelectedCompare">Delete Run</button>
    </div>
</div>




@code {
    public int SelectedRun { get; set; }

    public int SelectedCompareRun { get; set; }

    public List<string> Runs = AttackSurfaceAnalyzerClient.DatabaseManager.GetRuns();

    public List<(string firstRunId, string secondRunId, string analysesHash, RUN_STATUS runStatus)> CompareRuns = AttackSurfaceAnalyzerClient.DatabaseManager.GetCompareRuns();

    public void DeleteSelected()
    {
        AttackSurfaceAnalyzerClient.DatabaseManager.DeleteRun(Runs[SelectedRun]);
        Runs = AttackSurfaceAnalyzerClient.DatabaseManager.GetRuns();
        this.StateHasChanged();
    }

    public void DeleteSelectedCompare()
    {
        AttackSurfaceAnalyzerClient.DatabaseManager.DeleteCompareRun(CompareRuns[SelectedCompareRun].firstRunId, CompareRuns[SelectedCompareRun].secondRunId, CompareRuns[SelectedCompareRun].analysesHash);
        CompareRuns = AttackSurfaceAnalyzerClient.DatabaseManager.GetCompareRuns();
        this.StateHasChanged();
    }
}
